﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcEngine.Core.Pagination;

namespace MvcEngine.Core.Extensions
{
    public static class IQueryableExtensions
    {
        public static IPagination<T> GetPage<T>(this IEnumerable<T> query, int pageIndex, int pageSize)
        {
            return query.AsPagination(pageIndex, pageSize);
        }

        public static IOrderedEnumerable<TSource> Sort<TSource, TKey>(this IEnumerable<TSource> query, Func<TSource, TKey> expression, bool ascending)
        {
            if(ascending)
                return query.OrderBy(expression);
            return query.OrderByDescending(expression);
        }
    }
}
